﻿Public Class xtf_LISTADOvehiculo_

    Public Overrides Sub IniciarLista()
        Try
            gdc_general.BeginUpdate()
            gdc_general.DataSource = dtt_DataTable
            'ulg_Lista.DisplayLayout.GroupByBox.Style = Infragistics.Win.UltraWinGrid.GroupByBoxStyle.Full

            'Creacion y carga de Cuentas
            dtt_DataTable.Columns.Add("Identificador (ID)")
            dtt_DataTable.Columns.Add("Marca")
            dtt_DataTable.Columns.Add("Modelo")
            dtt_DataTable.Columns.Add("Año")
            dtt_DataTable.Columns.Add("Patente")
            dtt_DataTable.Columns.Add("Inventario")
            dtt_DataTable.Columns.Add("Denominacion")
            dtt_DataTable.Columns.Add("Tipo")
            dtt_DataTable.Columns.Add("Personal")

            gdv_general.PopulateColumns(dtt_DataTable)

            Dim obj_vehiculo_ As New cls_vehiculo_
            If obj_vehiculo_.CargarTodos(ObtenerRegistroEstado) Then
                For Each vehiculo As cls_vehiculo_ In obj_vehiculo_.Items
                    AgregarItem(vehiculo)
                Next
            End If
            'ulg_Lista.DataBind()

            FiltrarColumnas()
            gdc_general.EndUpdate()
        Catch ex As Exception
            'Dim frmError As New frm_ErrorManager(ex.Message)
        End Try
    End Sub

    Public Function AgregarItem(ByRef vehiculo As cls_vehiculo_) As DataRow
        Dim Row As DataRow = dtt_DataTable.NewRow
        Row("Identificador (ID)") = vehiculo.idvehiculo
        If Not IsNothing(vehiculo.marca) Then
            Row("Marca") = vehiculo.marca.ToString
        End If
        If Not IsNothing(vehiculo.modelo) Then
            Row("Modelo") = vehiculo.modelo.ToString
        End If
        Row("Año") = vehiculo.año
        Row("Patente") = vehiculo.patente
        Row("Inventario") = vehiculo.inventario
        Row("Denominacion") = vehiculo.denominacion
        If Not IsNothing(vehiculo.vehiculotipo) Then
            Row("Tipo") = vehiculo.vehiculotipo.ToString
        End If
        If Not IsNothing(vehiculo.personal) Then
            Row("Personal") = vehiculo.personal.ToString
        End If


        dtt_DataTable.Rows.Add(Row)
        'ulg_Lista.Rows(ulg_Lista.Rows.Count - 1).Height = 19
        Return Row
    End Function

    Public Sub ModificarItem(ByRef vehiculo As cls_vehiculo_, ByRef ulg_row As DataRow)
        ulg_row("Identificador (ID)") = vehiculo.idvehiculo
        ulg_row("Identificador (ID)") = vehiculo.idvehiculo
        If Not IsNothing(vehiculo.marca) Then
            ulg_row("Marca") = vehiculo.marca.ToString
        Else
            ulg_row("Marca") = ""
        End If
        If Not IsNothing(vehiculo.modelo) Then
            ulg_row("Modelo") = vehiculo.modelo.ToString
        Else
            ulg_row("Modelo") = ""
        End If
        ulg_row("Año") = vehiculo.año
        ulg_row("Patente") = vehiculo.patente
        ulg_row("Inventario") = vehiculo.inventario
        ulg_row("Denominacion") = vehiculo.denominacion
        If Not IsNothing(vehiculo.vehiculotipo) Then
            ulg_row("Tipo") = vehiculo.vehiculotipo.ToString
        Else
            ulg_row("Tipo") = ""
        End If
        If Not IsNothing(vehiculo.personal) Then
            ulg_row("Personal") = vehiculo.personal.ToString
        Else
            ulg_row("Personal") = ""
        End If
    End Sub

    Public Sub New()

        Me.Cursor = Cursors.WaitCursor
        InitializeComponent()
        PERMISONuevo = "013003002"
        PERMISOModificar = "013003003"
        PERMISOEliminar = "013003004"
        PERMISOImprimir = "013003005"
        Me.Text = lbl_modulo.Text : lbl_modulodescripcion.Text = "Listado de " & lbl_modulo.Text & "."
        IniciarLista()
        Me.Cursor = Cursors.Default

    End Sub

End Class

